﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaWpfBase;
using GWApplication;


namespace GWPresentation
{

    public class TvConceptualVM:MDTVIViewModel
    {
        public TvConceptualVM(MDTVIViewModel parent,ConceptualData conceptual)
            : base(parent)
        {


            this._conceptual = conceptual;

            this._conceptual.CMAdded += new EventHandler(_conceptual_CMAdded);
            this._conceptual.CMRemoved += new EventHandler(_conceptual_CMRemoved);

            this.LoadChildren();


        }


        void _conceptual_CMRemoved(object sender, EventArgs e)
        {

            ConceptualModel cm = sender as ConceptualModel;


            TvConceptualModelVM found = null;

            foreach (TvConceptualModelVM item in this.Children)
            {
                if (cm==item.ConceptualModel)
                {
                    found = item;

                    break;

                 
                    
                }
                
            }


            if (found!=null)
            {
                this.Children.Remove(found);
                
            }


            
        }

        void _conceptual_CMAdded(object sender, EventArgs e)
        {
            TvConceptualModelVM cmvm = new TvConceptualModelVM(this, sender as ConceptualModel);

            this.Children.Add(cmvm);

        }


        ConceptualData _conceptual;

        public override string Desc
        {
            get
            {
                return "概念数据";
            }
        }

        protected override void LoadChildren()
        {
            base.LoadChildren();



            foreach (ConceptualModel cm in this._conceptual.Models)
            {
                TvConceptualModelVM cmvm = new TvConceptualModelVM(this,cm);

                this.Children.Add(cmvm);
                
            }



        }



    }
}
